package com.googlecode.gxtmvp.rest.client;

import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.ModelComparer;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;

public class RestListStore<M extends ModelData> extends ListStore<M> {
  
  public static class IdComparer<M extends ModelData> implements ModelComparer<M> {
    @Override
    public boolean equals(M m1, M m2) {
      return m1 == m2 || m1 != null && m2 != null && m1.get("id") != null && m1.get("id").equals(m2.get("id"));
    }
  }
  
  public RestListStore(ListLoader<ListLoadResult<M>> loader) {
    super(loader);
    setModelComparer(new IdComparer<M>());
  }
  
}